using System;
using Unity.VisualScripting;
using UnityEngine;

public class Item : MonoBehaviour
{
    public NumItem numItem = null;//数值Item
    

    #region 构建Item
    private static readonly GameObject itemPrefab; //对应的预制体
    public static Item SpawnItem(Transform parent)
    {
        var go = (GameObject)Instantiate(Resources.Load("Prefab/Game/Item"), parent);
        return go.GetComponent<Item>();
    }
    

    #endregion

    #region 游戏逻辑
    public void SetNumItem(NumItem item)
    {
        numItem = item;
    }
    public bool hasNumber() //是否含有数值
    {
        return numItem != null;
    }
    //合并一个 Item,返回合并的数值,用于计算分数
    public void MergeNum(Item target)
    {
        target.numItem.notIsMergedNumber = false;
        target.numItem.Merge(); //合并
        numItem.Merged();//被合并
        numItem = null;

    }

    public void MoveNumItem(Item target)
    {
        target.numItem = numItem;
        numItem.transform.SetParent(target.transform);
        numItem.UpdatePosition();
        this.numItem = null;
    }
    #endregion
    
}
